/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GestionVentas.java
 *
 * Created on 17/03/2011, 12:16:59 PM
 */

package com.catosist.run.application.venta;

import com.catosist.run.application.Util.ColoredTableCellRenderer;
import com.catosist.run.application.Util.MiModelo;
import com.catosist.run.business.gestorcliente.GestorCliente;
import com.catosist.run.business.gestorcomprobante.GestorComprobante;
import com.catosist.run.services.ClienteDTO;
import com.catosist.run.services.ComprobanteDTO;
import java.util.Iterator;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.LinkedList;

import javax.swing.DefaultComboBoxModel;


/**
 *
 * @author igorov
 */
public class GestionVentas extends javax.swing.JFrame {

    /** Creates new form GestionVentas */
    public GestionVentas() {
        initComponents();
//        refresh();
    }

    public GestionVentas(GestorComprobante gestorComprobante, GestorCliente gestorCliente, char FacturasBoletasContrato) {
        initComponents();
        this.gestorComprobante = gestorComprobante;
        this.gestorCliente = gestorCliente;
        llenarClientes();
        llenarNumeroSerie();
        llenarAnhos();

        this.FacturasBoletasContratos = FacturasBoletasContrato;

//        filtroAnho = filtroMes = filtroNumeroSerie = filtroCliente = "Todos";

        refresh();
    }


    private void llenarClientes(){
        DefaultComboBoxModel modelCmbCliente = new DefaultComboBoxModel();
        modelCmbCliente.addElement("Todos");
        for (Iterator<ClienteDTO> it = gestorCliente.getAll().iterator(); it.hasNext();) {
            ClienteDTO clienteDTO = it.next();
            modelCmbCliente.addElement(clienteDTO.getId() + ", " + clienteDTO.getNombre());
        }
        this.cmbClientes.setModel(modelCmbCliente);
    }

    private void llenarNumeroSerie(){
        DefaultComboBoxModel modelCmbSeries = new DefaultComboBoxModel();
        modelCmbSeries.addElement("Todos");
        for (Iterator<ComprobanteDTO> it = gestorComprobante.getAllbySerie().iterator(); it.hasNext();) {
            ComprobanteDTO comprobanteDTO = it.next();
            modelCmbSeries.addElement(comprobanteDTO.getNumeroserie());
        }
        this.cmbNumeroSerie.setModel(modelCmbSeries);
    }

    private void llenarAnhos(){
        DefaultComboBoxModel modelCmbAnho = new DefaultComboBoxModel();
        modelCmbAnho.addElement("Todos");
        for (Iterator<Integer> it = gestorComprobante.getAllbyAnho().iterator(); it.hasNext();) {
            int anho = it.next();
            modelCmbAnho.addElement(anho);
        }
        this.cmbAnho.setModel(modelCmbAnho);
    }

    public JPanel getPanel(){
        return this.jPanel1;
    }

    public void recuperarComprobantesFacturas(){
        comprobanteDTOs = gestorComprobante.getAllFacturas();
        comprobanteDTOsFiltrados = comprobanteDTOs;
    }

    public void recuperarComprobantesBoletas(){
        comprobanteDTOs = gestorComprobante.getAllBoletas();
        comprobanteDTOsFiltrados = comprobanteDTOs;
    }

    public void recuperarComprobantesContratos(){
        comprobanteDTOs = gestorComprobante.getAllContratos();
        comprobanteDTOsFiltrados = comprobanteDTOs;
    }

    public void refresh() {
        switch(FacturasBoletasContratos){
            case 'f':
                recuperarComprobantesFacturas();
                break;
            case 'b':
                recuperarComprobantesBoletas();
                break;
            default:
                recuperarComprobantesContratos();
                break;
        }
        llenarGrilla();
        llenarAnhos();
    }

    private void llenarGrilla(){
        DefaultTableModel model = new MiModelo();
        model.addColumn("Id");
        model.addColumn("Numero");
        model.addColumn("Fecha");
        model.addColumn("Cliente");
        model.addColumn("Monto");
        model.addColumn("IGV");
        model.addColumn("Valor sin detraccion");
        model.addColumn("Detraccion");
        model.addColumn("Total");
        model.addColumn("Cancelacion");

        Float sumaMontos, sumaIgv, sumaSinDetraccion, sumaDetracciones, sumaTotales, sumaDeuda;
        sumaMontos = sumaIgv = sumaSinDetraccion = sumaDetracciones = sumaTotales = sumaDeuda = 0f;

        for (Iterator<ComprobanteDTO> it = comprobanteDTOsFiltrados.iterator(); it.hasNext();) {
            ComprobanteDTO comprobanteDTO = it.next();
            model.addRow(comprobanteDTO.toArray2());
            //Sumando todos los valores de los objetos filtrados
            sumaMontos += comprobanteDTO.getMonto();
            sumaIgv += comprobanteDTO.getIgv();
            sumaSinDetraccion += comprobanteDTO.getTotalsindetraccion();
            sumaDetracciones += comprobanteDTO.getDetraccion();
            sumaTotales += comprobanteDTO.getTotal();
            if (comprobanteDTO.getFcancelacion() == null) {
                sumaDeuda += (comprobanteDTO.getTotal() - comprobanteDTO.getAdelanto());
            }
        }
        this.jTable1.setModel(model);
        //Llenando con las sumatorias calculadas
        lblSumMontos.setText(formatearDecimal(sumaMontos));
        lblSumIGV.setText(formatearDecimal(sumaIgv));
        lblSumSinDetraccion.setText(formatearDecimal(sumaSinDetraccion));
        lblSumDetracciones.setText(formatearDecimal(sumaDetracciones));
        lblSumTotales.setText(formatearDecimal(sumaTotales));
        lblSumDeuda.setText(formatearDecimal(sumaDeuda));

        //Pintando las filas de todas las columnas
        for (int i = 0; i < jTable1.getColumnCount(); i++) {
            TableColumn col = jTable1.getColumnModel().getColumn(i);
            col.setCellRenderer(new ColoredTableCellRenderer());
        }
    }

    private String formatearDecimal(Float numero){
        return new DecimalFormat("0.00").format(numero);
    }

    
    public int getSelectedId() {
        return Integer.parseInt(this.jTable1.getValueAt(this.jTable1.getSelectedRow(),0).toString());
    }

    private void filtrar(){
        comprobanteDTOsFiltrados = new LinkedList<ComprobanteDTO>();
        for (Iterator<ComprobanteDTO> it = comprobanteDTOs.iterator(); it.hasNext();) {
            ComprobanteDTO comprobanteDTO = it.next();
            Calendar calendar = new GregorianCalendar();
            calendar.setTime(comprobanteDTO.getFingreso());

            boolean proposicionCliente = (cmbClientes.getSelectedIndex() == 0) ? true : comprobanteDTO.getClienteId() == filtroCliente;
            boolean proposicionNumeroSerie = (cmbNumeroSerie.getSelectedIndex() == 0) ? true : comprobanteDTO.getNumeroserie() == Integer.parseInt(filtroNumeroSerie);
            boolean proposicionAnho = (cmbAnho.getSelectedIndex() == 0) ? true : calendar.get(Calendar.YEAR) == Integer.parseInt(filtroAnho);
            boolean proposicionMes =(cmbMes.getSelectedIndex() == 0) ? true : calendar.get(Calendar.MONTH) == cmbMes.getSelectedIndex() - 1;


            if (proposicionCliente && proposicionNumeroSerie && proposicionAnho && proposicionMes) {
                    comprobanteDTOsFiltrados.add(comprobanteDTO);
            }
        }
        llenarGrilla();
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cmbClientes = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        cmbNumeroSerie = new javax.swing.JComboBox();
        jTextField4 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField3 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jTextField1 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        lblSumDetracciones = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        lblSumTotales = new javax.swing.JLabel();
        lblSumIGV = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        lblSumSinDetraccion = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        lblSumDeuda = new javax.swing.JLabel();
        lblSumMontos = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        cmbAnho = new javax.swing.JComboBox();
        cmbMes = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.catosist.run.application.desktopapplication.DesktopApplication.class).getContext().getResourceMap(GestionVentas.class);
        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        cmbClientes.setFont(resourceMap.getFont("cmbClientes.font")); // NOI18N
        cmbClientes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbClientes.setName("cmbClientes"); // NOI18N
        cmbClientes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbClientesItemStateChanged(evt);
            }
        });

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        cmbNumeroSerie.setFont(resourceMap.getFont("cmbNumeroSerie.font")); // NOI18N
        cmbNumeroSerie.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbNumeroSerie.setName("cmbNumeroSerie"); // NOI18N
        cmbNumeroSerie.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbNumeroSerieItemStateChanged(evt);
            }
        });

        jTextField4.setBackground(resourceMap.getColor("jTextField4.background")); // NOI18N
        jTextField4.setEditable(false);
        jTextField4.setName("jTextField4"); // NOI18N

        jLabel4.setFont(resourceMap.getFont("jLabel4.font")); // NOI18N
        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTable1.setName("jTable1"); // NOI18N
        jScrollPane1.setViewportView(jTable1);

        jTextField3.setBackground(resourceMap.getColor("jTextField3.background")); // NOI18N
        jTextField3.setEditable(false);
        jTextField3.setName("jTextField3"); // NOI18N

        jTextField2.setBackground(resourceMap.getColor("jTextField2.background")); // NOI18N
        jTextField2.setEditable(false);
        jTextField2.setName("jTextField2"); // NOI18N

        jTextField1.setBackground(resourceMap.getColor("jTextField1.background")); // NOI18N
        jTextField1.setEditable(false);
        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        jLabel3.setFont(resourceMap.getFont("jLabel3.font")); // NOI18N
        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel5.setFont(resourceMap.getFont("jLabel5.font")); // NOI18N
        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel7.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel13.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        lblSumDetracciones.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        lblSumDetracciones.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSumDetracciones.setText(resourceMap.getString("lblSumDetracciones.text")); // NOI18N
        lblSumDetracciones.setName("lblSumDetracciones"); // NOI18N

        jLabel9.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jLabel15.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        lblSumTotales.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        lblSumTotales.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSumTotales.setText(resourceMap.getString("lblSumTotales.text")); // NOI18N
        lblSumTotales.setName("lblSumTotales"); // NOI18N

        lblSumIGV.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        lblSumIGV.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSumIGV.setText(resourceMap.getString("lblSumIGV.text")); // NOI18N
        lblSumIGV.setName("lblSumIGV"); // NOI18N

        jLabel11.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        lblSumSinDetraccion.setFont(resourceMap.getFont("jLabel11.font")); // NOI18N
        lblSumSinDetraccion.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSumSinDetraccion.setText(resourceMap.getString("lblSumSinDetraccion.text")); // NOI18N
        lblSumSinDetraccion.setName("lblSumSinDetraccion"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        lblSumDeuda.setFont(resourceMap.getFont("lblSumDeuda.font")); // NOI18N
        lblSumDeuda.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSumDeuda.setText(resourceMap.getString("lblSumDeuda.text")); // NOI18N
        lblSumDeuda.setName("lblSumDeuda"); // NOI18N

        lblSumMontos.setFont(resourceMap.getFont("lblSumMontos.font")); // NOI18N
        lblSumMontos.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lblSumMontos.setText(resourceMap.getString("lblSumMontos.text")); // NOI18N
        lblSumMontos.setName("lblSumMontos"); // NOI18N

        jLabel8.setFont(resourceMap.getFont("jLabel8.font")); // NOI18N
        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        cmbAnho.setFont(resourceMap.getFont("cmbAnho.font")); // NOI18N
        cmbAnho.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbAnho.setName("cmbAnho"); // NOI18N
        cmbAnho.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbAnhoItemStateChanged(evt);
            }
        });

        cmbMes.setFont(resourceMap.getFont("cmbMes.font")); // NOI18N
        cmbMes.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Todos", "Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Setiembre", "Octubre", "Noviembre", "Diciembre" }));
        cmbMes.setName("cmbMes"); // NOI18N
        cmbMes.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cmbMesItemStateChanged(evt);
            }
        });

        jLabel10.setFont(resourceMap.getFont("jLabel10.font")); // NOI18N
        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 939, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel13)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblSumDetracciones, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblSumMontos, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(85, 85, 85)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblSumIGV, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addGap(45, 45, 45)
                                .addComponent(lblSumTotales, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 109, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(lblSumSinDetraccion, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(lblSumDeuda, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(jLabel3))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(jLabel5)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 78, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(jLabel4))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(4, 4, 4)
                                .addComponent(jLabel6)))
                        .addGap(223, 223, 223))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmbAnho, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmbClientes, javax.swing.GroupLayout.PREFERRED_SIZE, 487, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(37, 37, 37)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmbNumeroSerie, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmbMes, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(cmbClientes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(cmbAnho, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbNumeroSerie, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cmbMes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel10))))
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 406, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel11)
                            .addComponent(lblSumSinDetraccion)
                            .addComponent(lblSumMontos)
                            .addComponent(jLabel9)
                            .addComponent(lblSumIGV))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(lblSumDetracciones)
                            .addComponent(jLabel15)
                            .addComponent(lblSumTotales)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(lblSumDeuda)))
                .addContainerGap(33, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void cmbClientesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbClientesItemStateChanged
        // TODO add your handling code here:
        String clienteTmp = cmbClientes.getSelectedItem().toString();
        if (clienteTmp.compareTo("Todos") != 0)
            filtroCliente = Integer.valueOf(clienteTmp.substring(0, clienteTmp.indexOf(",")));
        filtrar();
    }//GEN-LAST:event_cmbClientesItemStateChanged

    private void cmbNumeroSerieItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbNumeroSerieItemStateChanged
        // TODO add your handling code here:
        filtroNumeroSerie = cmbNumeroSerie.getSelectedItem().toString();
        filtrar();
    }//GEN-LAST:event_cmbNumeroSerieItemStateChanged

    private void cmbAnhoItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbAnhoItemStateChanged
        // TODO add your handling code here:
        filtroAnho = cmbAnho.getSelectedItem().toString();
        filtrar();
    }//GEN-LAST:event_cmbAnhoItemStateChanged

    private void cmbMesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cmbMesItemStateChanged
        // TODO add your handling code here:
        filtroMes = cmbMes.getSelectedItem().toString();
        filtrar();
    }//GEN-LAST:event_cmbMesItemStateChanged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GestionVentas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbAnho;
    private javax.swing.JComboBox cmbClientes;
    private javax.swing.JComboBox cmbMes;
    private javax.swing.JComboBox cmbNumeroSerie;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JLabel lblSumDetracciones;
    private javax.swing.JLabel lblSumDeuda;
    private javax.swing.JLabel lblSumIGV;
    private javax.swing.JLabel lblSumMontos;
    private javax.swing.JLabel lblSumSinDetraccion;
    private javax.swing.JLabel lblSumTotales;
    // End of variables declaration//GEN-END:variables
    private GestorComprobante gestorComprobante;
    private GestorCliente gestorCliente;
    private List<ComprobanteDTO> comprobanteDTOs;
    private List<ComprobanteDTO> comprobanteDTOsFiltrados;
    private char FacturasBoletasContratos;
//    private DefaultTableModel model;
    private String filtroAnho;
    private String filtroMes;
    private String filtroNumeroSerie;
    private int filtroCliente;
}
